import java.util.Scanner;

public class 特别数的和 {
    static long sum;
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n =  s.nextInt();

        for(int i=1;i<=n;i++) {
            if(judge(i)) sum+=i;
        }
        System.out.println(sum);
    }
    private static boolean judge(int n) {
        int m = n;
        while(n!=0) {
            m=n%10;
            if(m==1 || m==2 || m==0 || m==9) return true;
            n/=10;
        }
        return false;
    }

}
